package io.github.hadyang.leetcode.offer;

import io.github.hadyang.leetcode.ListNode;
import java.util.ArrayList;

/** @author haoyang.shi */
public class LinkPrintFromTail {

  public ArrayList<Integer> printListFromTailToHead(ListNode listNode) {
    ArrayList<Integer> res = new ArrayList<>();

    print(res, listNode);

    return res;
  }

  private void print(ArrayList<Integer> res, ListNode listNode) {
    if (listNode == null) return;

    print(res, listNode.next);

    res.add(listNode.val);
  }
}
